import Vue from 'vue'
import Router from 'vue-router'
import LoGin from '@/page/login.vue'
import Index from '@/page/index/Index.vue'
import Home from '@/page/index/Home.vue'
import Communication from '@/page/index/Communication.vue'
import News from '@/page/index/News.vue'
import My from '@/page/My.vue'

import Department from '@/page/my/Department.vue'
import Personal from '@/page/my/Personal.vue'
import Recommend from '@/page/my/Recommend.vue'
import CashWithdrawal from '@/page/my/CashWithdrawal.vue'
import WithdrawalsRecord from '@/page/my/WithdrawalsRecord.vue'
import Details from '@/page/my/Details.vue'
import MyInformation from '@/page/my/MyInformation.vue'
import PersonalDetails from '@/page/my/PersonalDetails.vue'
import DepartmentDetails from '@/page/my/DepartmentDetails.vue'
import Code from '@/page/my/Code.vue'
import Code2 from '@/page/my/Code2.vue'
import QrCode from '@/page/my/QrCode.vue'
import MyCode from '@/page/my/MyCode.vue'

import Member from '@/page/my/recommend/Member.vue'
import Record from '@/page/my/recommend/Record.vue'

//会议预定分享
import MeetingCode_first from '@/page/my/Meeting/MeetingCode_first.vue'
import Meeting_Details from '@/page/my/Meeting/Meeting_Details.vue'
import Notice from '@/page/my/Meeting/Notice.vue'
import Notice_edit from '@/page/my/Meeting/Notice_edit.vue'
import MeetingCode_two from '@/page/my/Meeting/MeetingCode_two.vue'

//代客预定
import SubstituteBooking from '@/page/my/SubstituteBooking/index.vue'
import SubstituteBookingDetail from '@/page/my/SubstituteBooking/detail.vue'
import SubstituteBookingAdd from '@/page/my/SubstituteBooking/add.vue'
import SubstituteBookingCode from '@/page/my/SubstituteBooking/code.vue'


import {
  width
} from 'window-size';
Vue.use(Router)

const router = new Router({
  mode: "history",
  routes: [{
      path: '/LoGin',
      name: 'LoGin',
      meta: {
        title: '登录'
      },
      component: LoGin
    },
    {
      path: '/',
      name: 'Index',
      redirect: '/index/My'
    },
    {
      path: '/index',
      redirect: '/index/My',
      component: Index,
      children: [{
          path: '/index/Communication',
          name: 'Communication',
          component: Communication,
        },
        {
          path: '/index/home',
          name: 'Home',
          component: Home,
        },
        {
          path: '/index/News',
          name: 'News',
          component: News,
        },
        {
          path: '/index/My',
          name: 'My',
          meta: {
            title: '个人中心'
          },
          component: My,
        }
      ]
    },
    {
      path: '/my/Personal',
      name: 'Personal',
      meta: {
        title: '个人绩效'
      },
      component: Personal
    },
    {
      path: '/my/Department',
      name: 'Department',
      meta: {
        title: '部门绩效'
      },
      component: Department
    },
    {
      path: '/my/Recommend',
      name: 'Recommend',
      meta: {
        title: '邀请有礼'
      },
      component: Recommend
    },
    {
      path: '/my/recommend/Member',
      name: 'Member',
      meta: {
        title: '我邀请的会员'
      },
      component: Member
    },
    {
      path: '/my/recommend/Record',
      name: 'Record',
      meta: {
        title: '订单奖励记录'
      },
      component: Record
    },
    {
      path: '/my/code',
      name: 'code',
      component: Code
    },
    {
      path: '/my/code2',
      name: 'code2',
      component: Code2
    },
    {
      path: '/my/QrCode',
      name: 'QrCode',
      meta: {
        title: '邀请有礼'
      },
      component: QrCode
    },
    {
      path: '/my/MyCode',
      name: 'MyCode',
      meta: {
        title: '我的二维码'
      },
      component: MyCode
    },
    {
      path: '/my/CashWithdrawal',
      name: 'CashWithdrawal',
      meta: {
        title: '立即提现'
      },
      component: CashWithdrawal
    },
    {
      path: '/my/WithdrawalsRecord',
      name: 'WithdrawalsRecord',
      meta: {
        title: '提现记录'
      },
      component: WithdrawalsRecord
    },
    {
      path: '/my/Details',
      name: 'Details',
      meta: {
        title: '个人绩效目标'
      },
      component: Details
    },
    {
      path: '/my/MyInformation',
      name: 'MyInformation',
      meta: {
        title: '我的信息'
      },
      component: MyInformation
    },
    {
      path: '/my/PersonalDetails',
      name: 'PersonalDetails',
      meta: {
        title: '个人绩效目标'
      },
      component: PersonalDetails
    },
    {
      path: '/my/DepartmentDetails',
      name: 'DepartmentDetails',
      meta: {
        title: '部门绩效目标'
      },
      component: DepartmentDetails
    },
    //会议分享
    {
      path: '/my/Meeting/MeetingCode_first',
      meta: {
        title: '会议预定',
        id: 1
      },
      component: MeetingCode_first
    },
    {
      path: '/my/Meeting/Meeting_Details',
      meta: {
        title: '会议预定',
        id: 1
      },
      component: Meeting_Details
    },
    {
      path: '/my/Meeting/Notice',
      meta: {
        title: '会议须知',
        id: 1
      },
      component: Notice
    },
    {
      path: '/my/Meeting/Notice_edit',
      meta: {
        title: '会议须知',
        id: 1
      },
      component: Notice_edit
    },
    {
      path: '/my/Meeting/MeetingCode_two',
      meta: {
        title: '会议须知',
        id: 1
      },
      component: MeetingCode_two
    },
    {
      path: '/my/SubstituteBooking/index',
      meta: {
        title: '代客预定',
      },
      component: SubstituteBooking
    },
    {
      path: '/my/SubstituteBooking/detail',
      meta: {
        title: '代客预定',
      },
      component: SubstituteBookingDetail
    },
    {
      path: '/my/SubstituteBooking/add',
      meta: {
        title: '代客预定',
      },
      component: SubstituteBookingAdd
    },
    {
      path: '/my/SubstituteBooking/code',
      name: 'BookingCode',
      meta: {
        title: '代客预定',
      },
      component: SubstituteBookingCode
    },

  ]
})

router.beforeEach((to, from, next) => {
  console.log(to)
  var FirstUrl = sessionStorage.getItem('FirstUrl')
  if (FirstUrl == null) {
    sessionStorage.setItem('FirstUrl', window.location.href)
    var arrstr = sessionStorage.getItem('FirstUrl')
  }
  if (to.query.token != undefined || to.query.iosToken != undefined) {
    next(); //前往下一个页面
  } else {
    if (to.name !== 'LoGin' && !sessionStorage.getItem('token')) {
      if (to.name == 'QrCode' || to.meta.id == 1 || to.name == 'BookingCode') {
        next(); //前往下一个页面
      } else {
        console.log('111');
        next('/login');
      }
    } else {
      next(); //前往下一个页面
    }
  }
})
export default router;
